package org.example.caltax;

/**
 * 封装每个容易变化的税率信息
 */
public class TaxSection {
    //薪资的最低边界
    private double salStart;
    //薪资的最高边界
    private double salEnd;
    //税率
    private double tax;

    public TaxSection() {
    }

    public TaxSection(double salStart, double salEnd, double tax) {
        this.salStart = salStart;
        this.salEnd = salEnd;
        this.tax = tax;
    }
    /*
    根据薪资计算该对象范围内的税费
     */
    public double calTax(double salary){
        if (salary <= salStart) {
            return 0.0;
        }
        return xyz(salary);
    }

    private double xyz(double salary) {
        double taxCollectedAmount = salary > salEnd ? salEnd - salStart : salary - salStart;
        return taxCollectedAmount * tax;
    }
}
